@extends('admin.common.main')
@section('css')
    {{--  引入webuploader css 异步文件上传  --}}
    <link rel="stylesheet" type="text/css" href="/webuploader/webuploader.css">
@endsection
@section('cnt')
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 文章中心
        <span class="c-gray en">&gt;</span> 文章添加
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>

    <article class="page-container">

        @include('admin.common.validate')
        @include('admin.common.msg')

        <form action="{{ route('admin.article.update',$article) }}" method="post"
              class="form form-horizontal">
            @csrf
            @method('put')
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>文章标题：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" name="title" value="{{ $article->title }}">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>文章简介：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" name="desn" value="{{ $article->desn }}" autocomplete="off">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>文章封面：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    {{--                    <input type="file" class="input-text" name="pic" autocomplete="off">--}}
                    <input type="hidden" id="pic" name="pic" value="{{ $article->pic }}">
                    <div id="uploader-demo">
                        <!--用来存放item-->
                        <div id="fileList" class="uploader-list">
                            <img src="{{ $article->pic }}" alt="你好" id="img" style="width: 160px;height: 100px">
                        </div>
                        <br>
                        <div id="filePicker">选择图片</div>
                    </div>

                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">
                    <span class="c-red">*</span>文章内容：
                </label>
                <div class="formControls col-xs-8 col-sm-9">
                    <textarea name="body" id="body">{{ $article->body }}</textarea>
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="修改文章">
                </div>
            </div>
        </form>
    </article>
@endsection

@section('js')
    {{--// 引入验证的jquery--}}
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>

    {{-- webuploader js 异步文件上传 --}}
    <script type="text/javascript" src="/webuploader/webuploader.js"></script>

    <script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script>
        // 富文本
        var ue = UE.getEditor('body');

        // webupload
        var uploader = WebUploader.create({
            // 选完文件后，是否自动上传。
            auto: true,
            // swf文件路径
            swf: '/js/Uploader.swf',
            // post上传的携带的数据
            formData: {
                _token: "{{ csrf_token() }}"
            },
            // 文件接收服务端。
            server: '{{ route('admin.article.upimg') }}',
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: {
                id: '#filePicker',
                // 是否允许同时上传多个文件
                multiple: false,
            },
            // 只允许选择图片文件。
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });
        // 图片上传成功
        uploader.on('uploadSuccess', (file, ret) => {
            // console.log(ret.src);
            $('#pic').val(ret.src);
            $('#img').attr('src',ret.src);
        });

    </script>
@endsection
